﻿Imports TNCDAL
Imports System.Data.Linq
Imports System.Linq


Public Class CFee
    Dim db As New TanNamChinhDataContext

    Public Function SelectAllRecord(ByVal id_FeeType As Integer) As IQueryable(Of tblFee)
        Dim fee = From p In db.tblFees
                  Where p.ID_FeeType = id_FeeType And p.IsActive = True
                  Select p
                  Order By p.Rank

        Return fee
    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblFee
        Dim fee = (From p In db.tblFees
                 Where p.ID_fee = id
                 Select p).Single
        Return fee
    End Function

    Public Sub Insert(ByVal obj As tblFee)
        db.tblFees.InsertOnSubmit(obj)
        db.SubmitChanges()
    End Sub

    Public Sub Update(ByVal obj As tblFee)
        Dim fee = SelectRecordById(obj.ID_fee)
        fee.FeeName = obj.FeeName
        fee.FeeAbbreviated = obj.FeeAbbreviated
        fee.IsBill = obj.IsBill
        fee.Rank = obj.Rank
        db.SubmitChanges()
    End Sub

    Public Sub Delete(ByVal id As Integer)
        Dim fee = SelectRecordById(id)
        fee.IsActive = False
        db.SubmitChanges()
        'Dim fee = SelectRecordById(id)
        'db.tblFees.DeleteOnSubmit(fee)
        'db.SubmitChanges()
    End Sub
End Class
